package com.evaluation.kexingcp.psycho.evaluation.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.evaluation.kexingcp.common.core.util.R;
import com.evaluation.kexingcp.common.security.util.SecurityUtils;
import com.evaluation.kexingcp.psycho.evaluation.sys.entity.EvaluationTaskUserRelEntity;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationFactorRecordsService;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationScaleService;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationTaskService;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationTaskUserRelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 任务用户关联表
 *
 * @author pig
 * @date 2024-07-17 11:01:42
 */
@RestController
@RequestMapping("/evaluationTaskUserRel")
@Tag(description = "evaluationTaskUserRel", name = "任务用户关联表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EvaluationTaskUserRelController {

    private final EvaluationTaskUserRelService evaluationTaskUserRelService;
    private final EvaluationTaskService evaluationTaskService;
    private final EvaluationScaleService evaluationScaleService;
    private final EvaluationFactorRecordsService evaluationFactorRecordsService;

    public EvaluationTaskUserRelController(EvaluationTaskUserRelService evaluationTaskUserRelService, EvaluationTaskService evaluationTaskService, EvaluationScaleService evaluationScaleService, EvaluationFactorRecordsService evaluationFactorRecordsService) {
        this.evaluationTaskUserRelService = evaluationTaskUserRelService;
        this.evaluationTaskService = evaluationTaskService;
        this.evaluationScaleService = evaluationScaleService;
        this.evaluationFactorRecordsService = evaluationFactorRecordsService;
    }

    /**
     * 分页查询
     *
     * @param page                  分页对象
     * @param evaluationTaskUserRel 任务用户关联表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R getEvaluationTaskUserRelPage(@ParameterObject Page page, @ParameterObject EvaluationTaskUserRelEntity evaluationTaskUserRel) {
        LambdaQueryWrapper<EvaluationTaskUserRelEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(EvaluationTaskUserRelEntity::getUserId, SecurityUtils.getUser().getId());
        wrapper.eq(!Objects.isNull(evaluationTaskUserRel.getCompleted()), EvaluationTaskUserRelEntity::getCompleted, evaluationTaskUserRel.getCompleted());


        return R.ok(evaluationTaskUserRelService.getMyTask(page, evaluationTaskUserRel));
    }

    @GetMapping("/getMyUncompleteTask")
    public R getMyUncompleteTask() {
        return R.ok(evaluationTaskUserRelService.getMyUncompleteTask());
    }
}